package asia.lxq.cic.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(GlobalConfig.RESOURCE_ROOT+"**").addResourceLocations("file:"+GlobalConfig.CIC_ROOT);
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        File cicDir=new File(GlobalConfig.CIC_ROOT);
        if (!cicDir.exists()){
            boolean mkCicRoot = cicDir.mkdir();
            System.out.printf("初始化文件夹“%s” : %s\n",GlobalConfig.CIC_ROOT,mkCicRoot);
        }
    }
}
